package com.zq.user.controller;


import com.zq.common.util.Result;
import com.zq.user.dao.entity.UserAddress;
import com.zq.user.service.IUserAddressService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户地址表 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-06-02
 */
@RestController
@RequestMapping("/users/user-address")
public class UserAddressController {


    @Resource
    private IUserAddressService userAddressService;

//获取用户的地址列表（默认地址）
    @GetMapping("/auth/findUserAddressList")
    public Result<UserAddress> findUserAddressList() {
        UserAddress list = userAddressService.findUserAddressList();
        if (list == null) {
            return Result.errorData(null);
        }
        return Result.successData(list);
    }

    @GetMapping("/auth/getById/{id}")
    public Result<Object> getById(@PathVariable("id") Integer id) {
        return Result.successData(userAddressService.getById(id));
    }

//    获取用户的地址列表
    @GetMapping("/auth/getAll")
    public Result<List<UserAddress>> getAll() {
        List<UserAddress> userAddressList=     userAddressService.getAllList();
        return Result.successData(userAddressList);
    }
//    添加用户地址
    @PostMapping("/auth/save")
    public Result<Object> save(@RequestBody UserAddress userAddress) {
        userAddressService.saveUserAddr(userAddress);
        return Result.success();
    }

//    根据id删除用户地址
    @DeleteMapping("/auth/deleteById/{id}")
    public Result<Object> delete(@PathVariable("id") Integer id) {
        userAddressService.removeById(id);
        return Result.success();
    }
//    修改用户地址
    @PutMapping("/auth/update")
    public Result<Object> update(@RequestBody UserAddress userAddress) {
        userAddressService.updateByIdUserAddr(userAddress);
        return Result.success();
    }




}
